# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=cassava-megaparsec
pkgname=haskell-cassava-megaparsec
pkgver=2.0.4
pkgrel=100
pkgdesc="Megaparsec parser of CSV files that plays nicely with Cassava"
url="https://github.com/stackbuilders/cassava-megaparsec"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-cassava' 'haskell-megaparsec' 'haskell-unordered-containers'
         'haskell-vector')
makedepends=('ghc' 'uusi' 'haskell-hspec' 'haskell-hspec-megaparsec')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('9a9241e5251d049bc8f6ef40b6fc649ac55481e4609b4f7acb2d8772dd079519cfdeaea2d4cf03f8e55b75c7bff85251bfee962e842b46fe930dde25577a272a')

prepare() {
    cd $_hkgname-$pkgver
    uusi -u vector $_hkgname.cabal
}

build() {
    cd $_hkgname-$pkgver
    
    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.md
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.md
}
